<!DOCTYPE html>
<html lang="en">
<head>
    <include file="Public:header2" />
    <title>{:C('web_title')}</title>
	<style type="text/css">
		.band_succ{color:white;font-size:15px;margin-top:10px;}
		.band_succ a{color:white;}
	</style>
</head>
<body class="blackbg">
	<div id="container" class="logbg">
		<div class="log_title">
            <span class="back"><a href="javascript:history.go(-1)"></a></span>
            {$Think.lang.g_yx_bind}
        </div>
        <div class="logbot">
			<empty name="user['email']">
				<form>
					<input type="text" class="logipt" id="email" value="" placeholder="邮箱账号" />
					<div class="yzmbox">
						<input type="text" id="email_verify" value="" class="logipt yzmipt" placeholder="邮箱验证码" />
						<input type="button" id="regBtn" onclick="EmCode()" value="点击获取验证码" class="phonebut" />
					</div>
					<input type="button" class="logbut" value="绑定邮箱" title="绑定邮箱"  id="btn-up" onclick="Update()" />
				</form>
			<else/>
				<div class="band_succ">
				   <em></em>{$Think.lang.g_yx_has_bind}
				</div>
				<input type="text" value="{$Think.lang.g_yx_number}：{$user.email}" class="logipt" readonly/>
			</empty>
        </div>
	</div>
<script type="text/javascript">
function EmCode(){
	var email = $("#email").val();
	if (email == "" || email == null) {
		layer.tips('请输入电子邮箱', '#email', {tips: 3});
		return false;
	}
	layer.load(0, {shade: [0.5,'#8F8F8F']});
	$.post("{:U('Verify/emailbd')}", {
		email: email
	}, function (data) {
		layer.closeAll();
		if (data.status == 1) {
			//刷新验证码
			$('#regBtn').attr("disabled", "disabled");
			layer.msg(data.info, {icon: 1});
			var obj = $('#regBtn');
			var wait = 60;
			var interval = setInterval(function () {
				obj.css('backgroundColor', '#f6f6f6');
				obj.val(wait + '秒再次发送');
				wait--;
				if (wait < 0) {
					$('#regBtn').removeAttr("disabled");
					clearInterval(interval);
					obj.val('获取验证码');
					obj.css('backgroundColor', '#f6f6f6');
				}
				;
			}, 1000);
		} else {
			//刷新验证码
			layer.msg(data.info, {icon: 2});
			$('#regBtn').removeAttr("disabled");
			if (data.url) {
				window.location = data.url;
			}
		}
	}, "json");
}
function Update() {
	var email = $("#email").val();
	var email_verify = $("#email_verify").val();
	if (email == "" || email == null) {
		layer.tips('请输入邮箱账号', '#email', {tips: 3});
		return false;
	}
	if (email_verify == "" || email_verify == null) {
		layer.tips('请输入邮箱验证码', '#email_verify', {tips: 3});
		return false;
	}
	$.post("{:U('User/upemail')}", {
		email: email,
		email_verify: email_verify
	}, function (data) {
		if (data.status == 1) {
			layer.msg(data.info, {icon: 1});
			window.location = "{:U('User/email')}";
		} else {
			layer.msg(data.info, {icon: 2});
			if (data.url) {
				window.location = data.url;
			}
		}
	}, "json");
}
</script>
<include file="Public:footer" />
</body>
</html>